import request from '@/utils/request'

// 登录
export async function login(account, signature) {
  return request('/auth/login', {
    method: 'post',
    data: {
      walletAddress: account,
      signature,
      clientId: '48688a98fd39bc5133036266b274db1c'
    },
  })
}

// 获取网络列表
export function getNetwork(params) {
  return request('/network/list', {
    method: 'get',
    params: params,
  })
}

// 通过网络id，获取token列表
export function getTokenByNetId(params) {
  return request('/token/getTokenByNetId', {
    method: 'get',
    params: params,
  })
}

// 获取所有token 
export function getAllToken(params) {
  return request('/token/getAllToken', {
    method: 'get',
    params: params
  })
}

// 通过networkId获取network详情 
export function getByNetworkId(networkId) {
  return request(`/network/getByNetworkId/${networkId}`, {
    method: 'get',
  })
}

// 通过networkId获取定价代币 
export function getPriceTokenByNetId(params) {
  return request('/token/getPriceTokenByNetId', {
    method: 'get',
    params: params,
  })
}

// 创建挂单 
export  function createOffer(data) {
  return request('/offer/create', {
    method: 'post',
    data
  })
}

// 更新挂单链上信息
export function updateTxResult(data) {
  return request('/offer/updateTxResult', {
    method: 'post',
    data
  })
}

// 异常offer取消 
export function offerCatchError(id) {
  return request(`/offer/offerCatchError/${id}`, {
    method: 'delete',
  })
}
// 异常order取消 
export function orderCatchError(id) {
  return request(`/order/orderCatchError/${id}`, {
    method: 'delete',
  })
}

// 首页获取offer列表
export function getOfferPage(params) {
  return request('/offer/page', {
    method: 'get',
    params: params,
  })
}

// 通过id获取offerDetail
export function getOfferDetail(id) {
  return request(`/offer/detail/${id}`, {
    method: 'get',
  })
}

// 创建订单(填充报价,填充挂单)
export function createOrder(data) {
  return request('/order/create', {
    method: 'post',
    data
  })
}

// 更新订单链上信息 
export function updateOrderTxResult(data) {
  return request('/order/updateTxResult', {
    method: 'post',
    data
  })
}


// 我的挂单
export function getMyOfferPage(params) {
  return request('/offer/myOfferPage', {
    method: 'get',
    params: params,
  })
}

// 我的订单
export function getMyFillOrderPage(params) {
  return request('/order/myFillOrder', {
    method: 'get',
    params: params,
  })
}

// 我的订单数量 
export function getMyOrderCount(params) {
  return request('/order/myOrderCount', {
    method: 'get',
    params: params,
  })
}

// 订单历史 
export function getOrderHistory(params) {
  return request('/order/orderHistory', {
    method: 'get',
    params: params,
  })
}

// 更新offer状态 
export function updateOfferStatus(offerId) {
  return request(`/offer/updateStatus/${offerId}`, {
    method: 'put',
  })
}

// 更新order状态 
export function updateOrderStatus(orderId) {
  return request(`/order/updateStatus/${orderId}`, {
    method: 'put',
  })
}

// 需要我结算的订单 
export function getMySettleOrders(params) {
  return request('/order/mySettleOrders', {
    method: 'get',
    params
  })
}

// 批量更新settle状态 
export function updateStatusBatch(orderIds) {
  return request('/order/updateStatusBatch', {
    method: 'put',
    params: orderIds
  })
}

// 获取首页轮播图
export function getBannerList(params) {
  return request('/market/banner/list', {
    method: 'get',
    params: params
  })
}

// 心跳，防止token过期
export function heartbeat() {
  return request('/auth/heartbeat', {
    method: 'get',
  })
}

// 获取我的offer数量
export function getMyOfferNums(params) {
  return request('/offer/myOfferCount', {
    method: 'get',
    params
  })
}

// 获取我的order数量
export function getMyOrderNums(params) {
  return request('/order/myOrderCount', {
    method: 'get',
    params
  })
}

// 获取我已经结算的单
export function getMySettledOrders(params) {
  return request('/order/mySettledOrders', {
    method: 'get',
    params
  })
}